//
//  VistorRegisterViewController.m
//  ppkc2016
//
//  Created by 拼凑的断音 on 16/3/3.
//  Copyright © 2016年 拼凑的断音. All rights reserved.
//

#import "VistorRegisterViewController.h"
#import "XXTool.h"
#import "SelectCountryAndAreaViewController.h"

#import "VisitorRigisterModel.h"
#import "PresentProjectMainCotroller.h"


@interface VistorRegisterViewController ()<UIActionSheetDelegate>

@property (nonatomic) UIScrollView* background;

@property (nonatomic) UIView *content;

@property (nonatomic) DKButton* selectLoginWay;

@property (nonatomic) UIView *accountBorder;

@property (nonatomic) DKButton* areaCodeShow;

@property (nonatomic) ProjectOnlyTextField *inputAccount;

@property (nonatomic) ProjectOnlyTextField *inputPassword;

@property (nonatomic) ProjectOnlyTextField *reInputPassword;

@property (nonatomic) DKButton *sendCode;

@property (nonatomic) ProjectOnlyTextField *inputCode;

@property (nonatomic,assign) int sendCodeTimerCount;

@property (nonatomic) NSTimer *timer;

@property (nonatomic) UIToolbar *topView;

@property(nonatomic,strong) UIImageView *line1;

@property(nonatomic,strong) UIImageView *line2;

@property(nonatomic,strong) UIImageView *line3;

@property(nonatomic,strong) UIImageView *line4;

@property(nonatomic,strong) UIImageView *line5;

@property(nonatomic,strong) UIImageView *line6;

@end

@implementation VistorRegisterViewController
{
    BOOL isPhoneRegister;
    VistorRegisterViewControllerUseType useType;
}

#pragma mark UI
-(UIScrollView*)background
{
    if (_background==nil)
    {
        _background = [[UIScrollView alloc] init];
        _background.backgroundColor = [UIColor clearColor];
        [self.view addSubview:_background];
    }
    return _background;
}

-(UIView*)content
{
    if (_content==nil)
    {
        _content = [[UIView alloc] init];
        _content.backgroundColor = [UIColor clearColor];
        [_content addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickBackground)]];
        _content.userInteractionEnabled = YES;
        [_background addSubview:_content];
    }
    return _content;
}


-(DKButton*)selectLoginWay
{
    if (_selectLoginWay==nil)
    {
        _selectLoginWay = [[DKButton alloc] init];
//        _selectLoginWay.layer.borderWidth = 1;
//        _selectLoginWay.layer.borderColor = [XXTool colorWithProject].CGColor;
//        _selectLoginWay.layer.cornerRadius = 5;
        _selectLoginWay.imagePosition = DKButtonImagePositionAtBegan;
        [_selectLoginWay setColor:[UIColor clearColor] ForState:DKButtonStateNormal];
        _selectLoginWay.font = [XXTool systemFontOfSize:17];
        _selectLoginWay.text = NSLocalizedString(@"邮箱", nil);
        _selectLoginWay.textColor = [XXTool colorWithProject];
        _selectLoginWay.imageTintColor = [XXTool colorWithProject];
//        _selectLoginWay.image = [UIImage imageNamed:@"向下箭头"];
//        _selectLoginWay.imageSize = CGSizeMake([XXTool getWidthWithScreenWidth:28], [XXTool getWidthWithScreenWidth:28]/2);
//        _selectLoginWay.imageTitleGap = [XXTool getWidthWithScreenWidth:24];
        [_selectLoginWay addTarget:self Select:@selector(clickSelectLoginWay) ForEvent:DKButtonEventPressedEnd];
        [_background addSubview:_selectLoginWay];
    }
    return _selectLoginWay;
}

-(UIImageView*)line1{
    if(_line1 == nil){
        _line1=[[UIImageView alloc]initWithImage:[[UIImage imageNamed:@"短线"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
        _line1.tintColor = [XXTool colorWithProject];
        [_background addSubview:_line1];
    }
    return _line1;
}

-(UIView*)accountBorder
{
    if (_accountBorder==nil)
    {
        _accountBorder = [[UIView alloc] init];
        _accountBorder.backgroundColor = [UIColor clearColor];
        [_background addSubview:_accountBorder];
    }
    return _accountBorder;
}

-(DKButton*)areaCodeShow
{
    if (_areaCodeShow==nil)
    {
        _areaCodeShow = [[DKButton alloc] init];
        _areaCodeShow.textColor = [XXTool colorWithProject];
        _areaCodeShow.font = [XXTool systemFontOfSize:17];
        [_areaCodeShow setColor:[UIColor clearColor] ForState:DKButtonStateNormal];
        [_areaCodeShow addTarget:self Select:@selector(clickSelectAreaCode) ForEvent:DKButtonEventPressedEnd];
        [_accountBorder addSubview:_areaCodeShow];
    }
    return _areaCodeShow;
}

-(ProjectOnlyTextField*)inputAccount
{
    if (_inputAccount==nil)
    {
        _inputAccount = [[ProjectOnlyTextField alloc] init];
        _inputAccount.textColor = [XXTool colorWithProject];
        _inputAccount.font = [XXTool systemFontOfSize:17];
        _inputAccount.placeholder = NSLocalizedString(@"请输入邮箱地址", nil);
        [_inputAccount setValue:[XXTool colorProjectWithAlpha:0.3] forKeyPath:@"_placeholderLabel.textColor"];
        [_accountBorder addSubview:_inputAccount];
    }
    return _inputAccount;
}

-(UIImageView*)line2{
    if(_line2 == nil){
        _line2=[[UIImageView alloc]initWithImage:[[UIImage imageNamed:@"长线"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
        _line2.tintColor = [XXTool colorWithProject];
        [_accountBorder addSubview:_line2];
    }
    return _line2;
}

-(ProjectOnlyTextField*)inputPassword
{
    if (_inputPassword==nil)
    {
        UIView *inputLeftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 5)];
        
        _inputPassword = [[ProjectOnlyTextField alloc] init];
        _inputPassword.textColor = [XXTool colorWithProject];
        _inputPassword.font = [XXTool systemFontOfSize:17];
//        _inputPassword.layer.borderWidth = 1;
//        _inputPassword.layer.borderColor = [XXTool colorWithProject].CGColor;
//        _inputPassword.layer.cornerRadius = 5;
        _inputPassword.leftView = inputLeftView;
        _inputPassword.secureTextEntry = YES;
        _inputPassword.leftViewMode = UITextFieldViewModeAlways;
        _inputPassword.placeholder = NSLocalizedString(@"请设置密码", nil);
        [_inputPassword setValue:[XXTool colorProjectWithAlpha:0.3] forKeyPath:@"_placeholderLabel.textColor"];
        [_background addSubview:_inputPassword];
    }
    return _inputPassword;
}

-(UIImageView*)line3{
    if(_line3 == nil){
        _line3=[[UIImageView alloc]initWithImage:[[UIImage imageNamed:@"长线"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
        _line3.tintColor = [XXTool colorWithProject];
        [_background addSubview:_line3];
    }
    return _line3;
}

-(ProjectOnlyTextField*)reInputPassword
{
    if (_reInputPassword==nil)
    {
        UIView *inputLeftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 5)];
        
        _reInputPassword = [[ProjectOnlyTextField alloc] init];
        _reInputPassword.textColor = [XXTool colorWithProject];
        _reInputPassword.font = [XXTool systemFontOfSize:17];
//        _reInputPassword.layer.borderWidth = 1;
//        _reInputPassword.layer.borderColor = [XXTool colorWithProject].CGColor;
//        _reInputPassword.layer.cornerRadius = 5;
        _reInputPassword.leftView = inputLeftView;
        _reInputPassword.secureTextEntry = YES;
        _reInputPassword.leftViewMode = UITextFieldViewModeAlways;
        _reInputPassword.placeholder = NSLocalizedString(@"请再次输入密码", nil);
        [_reInputPassword setValue:[XXTool colorProjectWithAlpha:0.3] forKeyPath:@"_placeholderLabel.textColor"];
        [_background addSubview:_reInputPassword];
    }
    return _reInputPassword;
}

-(UIImageView*)line4{
    if(_line4 == nil){
        _line4=[[UIImageView alloc]initWithImage:[[UIImage imageNamed:@"长线"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
        _line4.tintColor = [XXTool colorWithProject];
        [_background addSubview:_line4];
    }
    return _line4;
}

-(DKButton*)sendCode
{
    if (_sendCode==nil)
    {
        _sendCode = [[DKButton alloc] init];
        _sendCode.textColor = [XXTool colorWithProject];
        _sendCode.text = NSLocalizedString(@"验证码", nil);
//        _sendCode.layer.borderColor = [XXTool colorWithProject].CGColor;
//        _sendCode.layer.cornerRadius = 5;
//        _sendCode.layer.borderWidth = 1;
        [_sendCode setColor:[UIColor clearColor] ForState:DKButtonStateNormal];
        _sendCode.font = [XXTool systemFontOfSize:15];
        [_sendCode addTarget:self Select:@selector(clickSendCode) ForEvent:DKButtonEventPressedEnd];
        [_background addSubview:_sendCode];
    }
    return _sendCode;
}

-(UIImageView*)line5{
    if(_line5 == nil){
        _line5=[[UIImageView alloc]initWithImage:[[UIImage imageNamed:@"短线"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
        _line5.tintColor = [XXTool colorWithProject];
        [_background addSubview:_line5];
    }
    return _line5;
}

-(ProjectOnlyTextField*)inputCode
{
    if (_inputCode==nil)
    {
        UIView *inputLeftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 5)];
        
        _inputCode = [[ProjectOnlyTextField alloc] init];
        _inputCode.textColor = [XXTool colorWithProject];
        _inputCode.font = [XXTool systemFontOfSize:17];
//        _inputCode.layer.borderWidth = 1;
//        _inputCode.layer.borderColor = [XXTool colorWithProject].CGColor;
//        _inputCode.layer.cornerRadius = 5;
        _inputCode.leftView = inputLeftView;
        _inputCode.leftViewMode = UITextFieldViewModeAlways;
        _inputCode.placeholder = NSLocalizedString(@"请输入验证码", nil);
        [_inputCode setValue:[XXTool colorProjectWithAlpha:0.3] forKeyPath:@"_placeholderLabel.textColor"];
        [_background addSubview:_inputCode];
    }
    return _inputCode;
}

-(UIImageView*)line6{
    if(_line6 == nil){
        _line6=[[UIImageView alloc]initWithImage:[[UIImage imageNamed:@"长线"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
        _line6.tintColor = [XXTool colorWithProject];
        [_background addSubview:_line6];
    }
    return _line6;
}

-(UIToolbar*)topView
{
    if (_topView==nil)
    {
        //textview编辑完成
        _topView = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 30)];
        _topView.backgroundColor = [XXTool colorWithBackGround];
        [_topView setBarStyle:UIBarStyleDefault];
        UIBarButtonItem * btnSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
        
        UIBarButtonItem * doneButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"完成", nil) style:UIBarButtonItemStyleDone target:self action:@selector(clickTextFieldDone)];
        [doneButton setTintColor:[XXTool colorWithProject]];
        NSArray * buttonsArray = [NSArray arrayWithObjects:btnSpace, doneButton, nil];
        
        [_topView setItems:buttonsArray];
    }
    return _topView;
}


#pragma mark api

-(instancetype)initWithVistorRegisterViewControllerUseType:(VistorRegisterViewControllerUseType)use
{
    self = [super init];
    if (self)
    {
        useType = use;
    }
    return self;
}

#pragma mark sub
-(void)initParameter
{
    isPhoneRegister = NO;
}

-(void)initUI
{
    if (useType==VistorRegisterViewControllerUseToRegister)
    {
        [self.navigationItem setTitle:NSLocalizedString(@"注册", nil)];
    }
    else
    {
        [self.navigationItem setTitle:NSLocalizedString(@"忘记密码", nil)];
    }
    //[self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(clickleftBarCancel)]];
    [self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"提交", nil) style:UIBarButtonItemStylePlain target:self action:@selector(clickSubmitButton)]];
    [self background];
    [self content];
    [self selectLoginWay];
    [self line1];
    [self accountBorder];
    [self areaCodeShow];
    [self inputAccount];
    [self line2];
    [self inputPassword];
    [self line3];
    [self reInputPassword];
    [self line4];
    [self sendCode];
    [self inputCode];
    [self line5];
    [self line6];
}

-(void)refreshLayout:(CGRect)frame
{
    _background.frame = CGRectMake(0, 0, frame.size.width
                                   , frame.size.height);
    
    
    _selectLoginWay.frame = CGRectMake(29
                                       , 35
                                       , [XXTool getWidthWithScreenWidth:200]
                                       , 47);
    _line1.frame=CGRectMake(29, _selectLoginWay.frame.origin.y+_selectLoginWay.frame.size.height, _selectLoginWay.frame.size.width, 4);
    _accountBorder.frame = CGRectMake(_selectLoginWay.frame.origin.x+_selectLoginWay.frame.size.width+10
                                      , _selectLoginWay.frame.origin.y
                                      , frame.size.width-29*2-_selectLoginWay.frame.size.width-10
                                      , _selectLoginWay.frame.size.height);
    if (isPhoneRegister) //用手机注册/找回密码
    {
        _areaCodeShow.hidden = NO;
        _sendCode.hidden = NO;
        _inputCode.hidden = NO;
        _areaCodeShow.frame = CGRectMake(10
                                         , 15
                                         , [XXTool getWidthWithScreenWidth:80]
                                         , 17);
        _inputAccount.frame = CGRectMake(_areaCodeShow.frame.size.width+_areaCodeShow.frame.origin.x+10
                                         , 0
                                         , _accountBorder.frame.size.width-20-_areaCodeShow.frame.size.width-10
                                         , _accountBorder.frame.size.height);
        _inputAccount.placeholder = NSLocalizedString(@"请输入手机号", nil);
        if (_sendCodeTimerCount>0&&_sendCodeTimerCount<60) //解决键盘弹出刷新正在计数的sendCodeButton文字的bug
        {
            
        }
        else
        {
            _sendCode.text = NSLocalizedString(@"验证码", nil);
        }
        

    }
    else
    {
        _areaCodeShow.hidden = YES;
        if (useType==VistorRegisterViewControllerUseToRegister) //用邮箱注册
        {
            _sendCode.hidden = YES;
            _inputCode.hidden = YES;
            _line5.hidden=YES;
            _line6.hidden=YES;
        }
        else  //用邮箱找回密码
        {
            _sendCode.hidden = NO;
            _inputCode.hidden = NO;
            if (_sendCodeTimerCount>0&&_sendCodeTimerCount<60)
            {
                
            }
            else
            {
                _sendCode.text = NSLocalizedString(@"验证码", nil);
            }
        }
        _inputAccount.frame = CGRectMake(20, 0
                                         , _accountBorder.frame.size.width-20
                                         , _accountBorder.frame.size.height);
        

        _inputAccount.placeholder = NSLocalizedString(@"请输入邮箱地址", nil);
        _line2.frame=CGRectMake(20, _inputAccount.frame.origin.y+_inputAccount.frame.size.height, _inputAccount.frame.size.width, 4);
    
    }
    _inputPassword.frame = CGRectMake(_selectLoginWay.frame.origin.x
                                      , _selectLoginWay.frame.size.height+_selectLoginWay.frame.origin.y+14
                                      , frame.size.width-29*2
                                      , _selectLoginWay.frame.size.height);
    _line3.frame=CGRectMake(_inputPassword.frame.origin.x, _inputPassword.frame.origin.y+_inputPassword.frame.size.height, _inputPassword.frame.size.width, 4);
    
    _reInputPassword.frame = CGRectMake(_inputPassword.frame.origin.x
                                        , _inputPassword.frame.size.height+_inputPassword.frame.origin.y+14
                                        , _inputPassword.frame.size.width
                                        , _inputPassword.frame.size.height);
    _line4.frame=CGRectMake(_reInputPassword.frame.origin.x, _reInputPassword.frame.origin.y+_reInputPassword.frame.size.height, _reInputPassword.frame.size.width, 4);
    
    _sendCode.frame = CGRectMake(_selectLoginWay.frame.origin.x
                                 , _reInputPassword.frame.size.height+_reInputPassword.frame.origin.y+14
                                 , _selectLoginWay.frame.size.width
                                 , _selectLoginWay.frame.size.height);
    _line5.frame=CGRectMake(_selectLoginWay.frame.origin.x, _sendCode.frame.origin.y+_sendCode.frame.size.height, _sendCode.frame.size.width, 4);
    
    _inputCode.frame = CGRectMake(_accountBorder.frame.origin.x
                                  , _sendCode.frame.origin.y
                                  , _accountBorder.frame.size.width
                                  , _accountBorder.frame.size.height);
    _line6.frame=CGRectMake(_accountBorder.frame.origin.x, _inputCode.frame.origin.y+_inputCode.frame.size.height, _inputCode.frame.size.width, 4);
    
    if (isPhoneRegister)
    {
        _background.contentSize = CGSizeMake(frame.size.width
                                             , _inputCode.frame.size.height+_inputCode.frame.origin.y+20);
    }
    else
    {
        if (useType==VistorRegisterViewControllerUseToRegister)
        {
            _background.contentSize = CGSizeMake(frame.size.width
                                                 , _reInputPassword.frame.size.height+_reInputPassword.frame.origin.y+20);
        }
        else
        {
            _background.contentSize = CGSizeMake(frame.size.width
                                                 , _inputCode.frame.size.height+_inputCode.frame.origin.y+20);
        }
    }
    _content.frame = CGRectMake(0, 0, _background.contentSize.width
                                , _background.contentSize.height>_background.frame.size.height?_background.contentSize.height:_background.frame.size.height);
}

-(void)clickSelectAreaCode
{
    [SelectCountryAndAreaViewController selectCountryAndAreaViewControllerDidPushWithSourceViewControoler:self Compeletation:^(NSString *selectedCode) {
        if ([selectedCode isEqualToString:@""])
        {
            
        }
        else //只有用户选择了区号才刷新页面
        {
            _inputAccount.keyboardType = UIKeyboardTypeNumberPad;
            [_inputAccount setInputAccessoryView:self.topView];
            
            isPhoneRegister = YES;
            _selectLoginWay.text = NSLocalizedString(@"手机", nil);
            [self refreshLayout];
            _areaCodeShow.text = selectedCode;
        }
    }];
}

/**
 *  选择登录方式
 */
-(void)clickSelectLoginWay
{
//    UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:nil
//                                                        delegate:self cancelButtonTitle:NSLocalizedString(@"取消", nil) destructiveButtonTitle:nil otherButtonTitles:NSLocalizedString(@"手机", nil),NSLocalizedString(@"邮箱",nil), nil];
//    [action showInView:self.view];
}

/**
 *  点击发送验证码
 */
-(void)clickSendCode
{
    if (isPhoneRegister)
    {
        if ([_areaCodeShow.text isEqualToString:@""])
        {
            [SVProgressHUD showInfoWithStatus:NSLocalizedString(@"请选择区号", nil)];
            return;
        }
        if ([_inputAccount.text isEqualToString:@""])
        {
            [SVProgressHUD showInfoWithStatus:NSLocalizedString(@"请输入手机号", nil)];
            return;
        }
    }
    else
    {
        if ([_inputAccount.text isEqualToString:@""])
        {
            [SVProgressHUD showInfoWithStatus:NSLocalizedString(@"请输入邮箱地址", nil)];
            return;
        }
    }
    
    
    VistorRigiterUseDataModel *temp = [[VistorRigiterUseDataModel alloc] init];
    if (isPhoneRegister)
    {
        temp.way = VisitorRigisterUsePhone;
    }
    else
    {
        temp.way = VisitorRigisterUseEmail;
    }
    temp.areaCode = _areaCodeShow.text;
    temp.phoneNumberOrEmail = _inputAccount.text;
    [VisitorRigisterModel visitorRegisterDidClickWithNeedData:temp
                                                   completion:^(BOOL isSuccess) {
                                                       if (isSuccess)
                                                       {
                                                           _sendCode.text = @"60s";
                                                           _sendCodeTimerCount = 60;
                                                           _timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(sendCodeTimer) userInfo:nil repeats:YES];
                                                           [_timer fire];
                                                           _sendCode.userInteractionEnabled = NO;
                                                       }
                                                   }];

}

/**
 *  验证码计时
 */
-(void)sendCodeTimer
{
    _sendCodeTimerCount--;
    _sendCode.text = [NSString stringWithFormat:@"%ds",_sendCodeTimerCount];
    if (_sendCodeTimerCount<1)
    {
        _sendCode.userInteractionEnabled = YES;
        _sendCode.text = NSLocalizedString(@"验证码", nil);
        [_timer invalidate];
    }
}

/**
 *  取消登录
 */
-(void)clickleftBarCancel
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

/**
 *  提交注册
 */
-(void)clickSubmitButton
{
    if (isPhoneRegister)
    {
        if ([_areaCodeShow.text isEqualToString:@""])
        {
            [SVProgressHUD showInfoWithStatus:NSLocalizedString(@"请选择区号", nil)];
            return;
        }
        if ([_inputAccount.text isEqualToString:@""])
        {
            [SVProgressHUD showInfoWithStatus:NSLocalizedString(@"请输入手机号", nil)];
            return;
        }
    }
    else
    {
        if ([_inputAccount.text isEqualToString:@""])
        {
            [SVProgressHUD showInfoWithStatus:NSLocalizedString(@"请输入邮箱地址", nil)];
            return;
        }
    }
    if ([_inputPassword.text isEqualToString:@""])
    {
        [SVProgressHUD showInfoWithStatus:NSLocalizedString(@"请设置密码", nil)];
        return;
    }
    
    if (_inputPassword.text.length>12||_inputPassword.text.length<6)
    {
        [SVProgressHUD showInfoWithStatus:NSLocalizedString(@"密码长度必须为6~12位", nil)];
        return;
    }
    
    if ([_reInputPassword.text isEqualToString:@""])
    {
        [SVProgressHUD showInfoWithStatus:NSLocalizedString(@"请再次确认密码", nil)];
    }
    if (![_inputPassword.text isEqualToString:_reInputPassword.text])
    {
        [SVProgressHUD showInfoWithStatus:NSLocalizedString(@"两次输入的密码不一致", nil)];
        return;
    }
    
    if (isPhoneRegister||useType==VistorRegisterViewControllerUseToFindPassword)  //修改密码或手机注册需要验证码
    {
        if ([_inputCode.text isEqualToString:@""])
        {
            [SVProgressHUD showInfoWithStatus:NSLocalizedString(@"请输入验证码", nil)];
            return;
        }
    }
    
    VistorRigiterUseDataModel *temp = [[VistorRigiterUseDataModel alloc] init];
    if (isPhoneRegister)
    {
        temp.way = VisitorRigisterUsePhone;
    }
    else
    {
        temp.way = VisitorRigisterUseEmail;
    }
    temp.areaCode = _areaCodeShow.text;
    temp.phoneNumberOrEmail = _inputAccount.text;
    temp.verifyCode = _inputCode.text;
    temp.password = _inputPassword.text;
    
    if (useType==VistorRegisterViewControllerUseToFindPassword)
    {
        temp.regtype = @"2";
    }
    else
    {
        temp.regtype = @"1";
    }
    
    if (isPhoneRegister||useType==VistorRegisterViewControllerUseToFindPassword)
    {
        [VisitorRigisterModel submitRegistrationOrChangePassWord:temp completion:^(BOOL isSuccess) {
            if (isSuccess)
            {
                
                if (useType==VistorRegisterViewControllerUseToRegister)
                {
                    [self successSubmit];
                    
                }
                else
                {
                    [SVProgressHUD showSuccessWithStatus:NSLocalizedString(@"密码修改成功", nil)];
                }
            }
        }];
    }
    else
    {
        [VisitorRigisterModel mailSubmitRegister:temp
                                      completion:^(BOOL isSuccess) {
                                          if (isSuccess)
                                          {
                                              
                                              [self successSubmit];
                                          }
                                      }];
    }
}

/**
 *  成功注册
 */
-(void)successSubmit
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"sumbitSuccess" object:nil];
    [self clickleftBarCancel];
}

-(void)clickBackground
{
    [self.inputAccount resignFirstResponder];
    [self.inputPassword resignFirstResponder];
    [self.reInputPassword resignFirstResponder];
    [self.inputCode resignFirstResponder];
}

-(void)clickTextFieldDone
{
    [_inputAccount resignFirstResponder];
}

#pragma mark actionSheetDelegate
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch (buttonIndex)
    {
        case 0: //手机
        {
            
            [self clickSelectAreaCode];
            break;
        }
        case 1: //邮箱
        {
            _inputAccount.keyboardType = UIKeyboardTypeDefault;
            [_inputAccount setInputAccessoryView:nil];
            _selectLoginWay.text = NSLocalizedString(@"邮箱", nil);
            isPhoneRegister = NO;
            [self refreshLayout];
        }
            break;
            
        default:
            break;
    }

}

@end
